Micron Document




JavaScript syntax
part 47/59 · 107.4 KB total
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
foo();
baz("baz arg");
bar(); // "baz arg" (not "foo var") even though foo() has exited.
console.log(t); // Top

An anonymous function is simply a function without a name and can be written either using function or arrow notation. In these equivalent examples an anonymous function is passed to the map function and is applied to each of the elements of the array.cite-ref-20[20]

[1,2,3].map(function(x) { return x*2;); //returns [2,4,6]
[1,2,3].map((x) => { return x*2;}); //same result

A generator function is signified placing an * after the keyword function and contains one or more yield statements. The effect is to return a value and pause execution at the current state. Declaring an generator function returns an iterator. Subsequent calls to iterator.next() resumes execution until the next yield. When the iterator returns without using a yield statement there are no more values and the done property of the iterator is set to true.cite-ref-21[21]

With the exception of iOS devices from Apple, generators are not implemented for browsers on mobile devices. cite-ref-22[22]

function* generator() {
yield "red";
yield "green";
yield "blue";
}
let iterator=generator();
let current;
while(current=iterator.next().value)
console.log(current); //displays red, green then blue
console.log(iterator.next().done) //displays true

Async/await

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────